<?php

class DB {
    protected $link = false;

    public function __construct() {
        $this->link = $this->getDBLink();
    }
    
    private function getDBLink() {
        $server = '';
        $user   = '';
        $pass   = '';
        $db     = '';
        $link = mysql_connect($server,$user,$pass);
        if (!$link || !mysql_select_db($db,$link)) {
                echo mysql_error($this->link);
        }
        return $link;
    }
    
    public function quote($text) {
        return '\''.mysql_real_escape_string($text).'\'';
    }
    
    private function error() {
        echo mysql_error($this->link);
    }
    
    public function query($query) {
        $result = mysql_query($query,$this->link);
        if ($result === true) {
            return true;
        } elseif ($result === false) {
            $this->error();
        } else {
            $return = array();
            while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
                $return[] = $row;
            }
            return $return;
        }
        return false;
    }
}
